
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>东单办公系统</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="media/layui/css/layui.css" media="all">
    <script type="text/javascript" src="media/js/jquery.min.js"></script>
</head>
<body>

<div class="layui-container">
    <table id="tbdata" lay-filter="tbop"></table>
    <script type="text/html" id="barop">
       <a class="layui-btn layui-btn-mini" lay-event="edit">编辑</a>
        <a class="layui-btn layui-btn-danger layui-btn-mini" lay-event="del">删除</a>
    </script>
</div>
<script src="media/layui/layui.js"></script>
<script>
    layui.use('table', function () {
        var table = layui.table;
        table.render({
            id: 'id',
            elem: '#tbdata',
            url: '/findAllAskforleave' //数据接口
            ,
            page: {
                limits: [5, 10, 15, 20],
                limit: 5,
                first: '首页',
                last: '尾页',
                prev: '<em><<</em>' //上一页显示内容，默认显示 > <
                , next: '<em>>></em>'
                , layout: ['prev', 'page', 'next', 'count', 'limit', 'skip', 'refresh']
            } //开启分页
            ,

            minWidth: 20,
            size: 'lg',
            cols: [[ //表头
                {   field: 'id',
                    fixed: 'left',
                    title: 'ID',
                    sort:true
                },
                {
                    field: 'name',
                    align: 'center',
                    title: '姓名'

                    //fixed : 'left'
                },
                {
                    field: 'startTime',
                    align: 'center',
                    title: '请假起始时间',
                    width: 270,
                    sort:true
                }, {
                    field: 'endTime',
                    align: 'center',
                    title: '请假结束时间',
                    width: 270,
                    sort:true
                }, {
                    field: 'reason',
                    align: 'center',
                    title: '请假原因',
                    width: 270,
                    sort:true
                },
                {
                    field: 'right',
                    title: '操作',
                    align: 'center',
                    toolbar: "#barop",
                    fixed: 'right',
                    width: 200
                }
            ]]
        });
        //监听工具条
        table.on('tool(tbop)', function (obj) {
            var data = obj.data;

            console.log(data)

            if (obj.event === 'del') {
                layer.confirm('是否确认删除该行数据?',

                    function (index) {
                        $.ajax({
                            url: "/deleteAskforleave",
                            type: "POST",
                            data: "id="+data.id,
                            success: function (data) {
                                if (data.code == 1) {
                                    obj.del();//删除表格中的对应行数据
                                    layer.close(index);
                                    layer.msg("删除成功", {
                                        icon: 6
                                    });
                                    // alert("删除成功")
                                    window.location.href = "/askList.html?time="+Math.random();
                                } else {
                                    layer.msg("删除失败", {
                                        icon: 5
                                    });
                                }
                            }
                        });
                    });
            } else if (obj.event === 'edit') {//编辑 修改
                location.href = "/askUpdate?id=" + data.id;

            }
        });
    });
</script>

</body>
</html>